package com.wish.g01.financial.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.wish.g01.base.dto.FactorAppDto;
import com.wish.g01.base.dto.FactoringDto;
import com.wish.g01.base.entity.JrFactoring;
import com.wish.g01.base.service.ICwReceiptPlanService;
import com.wish.g01.base.service.IJrFactoringService;
import com.wish.g01.base.vo.FactoringDeatilVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wish.g01.common.log.annotation.Log;
import com.wish.g01.common.log.enums.BusinessType;
import com.wish.g01.common.security.annotation.PreAuthorize;
import com.wish.g01.common.core.web.controller.BaseController;
import com.wish.g01.common.core.web.domain.AjaxResult;
import com.wish.g01.common.core.utils.poi.ExcelUtil;
import com.wish.g01.common.core.web.page.TableDataInfo;

/**
 * 租约保理申请Controller
 * 
 * @author wish
 * @date 2022-05-29
 */
@RestController
@RequestMapping("/factoring")
public class TJrFactoringController extends BaseController
{
    @Autowired
    private IJrFactoringService iJrFactoringService;

    @Autowired
    private ICwReceiptPlanService iCwReceiptPlanService;

    /**
     * 查询租约保理申请列表
     */
    @PreAuthorize(hasPermi = "system:factoring:list")
    @GetMapping("/list")
    public TableDataInfo list(JrFactoring tJrFactoring)
    {
        startPage();
        List<JrFactoring> list = iJrFactoringService.list();
        return getDataTable(list);
    }


    /**
     * 获取租约保理申请详细信息
     */
    @PreAuthorize(hasPermi = "system:factoring:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(iJrFactoringService.getById(id));
    }
//
    /**
     * 新增租约保理申请
     */
    @PreAuthorize(hasPermi = "system:factoring:add")
//    @Log(title = "租约保理申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FactoringDto factoringDto)
    {
        boolean bool = iJrFactoringService.addIJrFactoring(factoringDto);
//        System.out.println("yyyyyy"+bool);
        return AjaxResult.success(bool);
    }

//    /**
//     * 修改租约保理申请
//     */
//    @PreAuthorize(hasPermi = "system:factoring:edit")
//    @Log(title = "租约保理申请", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TJrFactoring tJrFactoring)
//    {
//        return toAjax(tJrFactoringService.updateTJrFactoring(tJrFactoring));
//    }
//
//    /**
//     * 删除租约保理申请
//     */
//    @PreAuthorize(hasPermi = "system:factoring:remove")
//    @Log(title = "租约保理申请", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(tJrFactoringService.deleteTJrFactoringByIds(ids));
//    }


    @PostMapping("getFactoringDatil")
    public AjaxResult getFactoringDatil(@RequestBody FactorAppDto factorAppDto){
        FactoringDeatilVo factoringDeatilVo = iCwReceiptPlanService.factoringApply(factorAppDto);
        ArrayList<FactoringDeatilVo> factoringDeatilVos = new ArrayList<>();
        factoringDeatilVos.add(factoringDeatilVo);
        return AjaxResult.success(factoringDeatilVos);
    }
}
